home *** CD-ROM | disk | FTP | other *** search
Wrap
/* Tracking Layout Sample Program By Eric Mader, After Mike Fairman, Oliver Steele et. al. */ /* Copyright ©1989, 1990, 1991 Apple Computer, Inc. All rights reserved. */ #ifndef THINK_C #include <Quickdraw.h> #include <Fonts.h> #include <Windows.h> #include <Dialogs.h> #include <Events.h> #include <Memory.h> #include <Menus.h> #include <String.h> #include <Desk.h> #include <Script.h> #include <ToolUtils.h> #define thePort qd.thePort #define screenBits qd.screenBits #endif #include "graphics libraries.h" #include "qd library.h" #include "graphics debugging.h" #include "graphics routines.h" #include "graphics toolbox.h" #include "layout types.h" #include "layout routines.h" #include "layout library.h" /* This macro is useful for constructing fixed values */ #define f(a,b) (((fixed) (a) << 16) + (b)) /* various menu and dialog things */ enum {aboutDLOG = 128, appleMenuID = 128, fileMenuID, editMenuID}; /* resource ID's */ enum {okButton = 1, showsItem, authorItem}; enum { /* Apple Menu */ aboutCommand = 1, /* File Menu */ quitCommand = 1, /* Edit Menu */ undoCommand = 1, cutCommand, copyCommand, pasteCommand, clearCommand}; WindowPtr myWindow, whichWindow; gxViewPort myPort; Rect qdWindowRect; Rect growRect = {40, 40, 32767, 32767}; Rect bigRect = {-32768, -32768, 32767, 32767}; gxRectangle windowRect; MenuHandle appleMenu, fileMenu, editMenu; Boolean done = false; gxColor colorWhite = xRGB (0xFFFF, 0xFFFF, 0xFFFF); /* white */ gxColor hsvInitial = xHSV (0, 0xFFFF, 0xFFFF); /* red */ static void ShowAboutBox () { GrafPtr savePort; DialogPtr theDialog; short itemType; Handle itemHdl; Rect itemRect; short itemHit; GetPort(&savePort); theDialog = GetNewDialog(aboutDLOG, nil, (WindowPtr) -1); SetPort(theDialog); GetDItem(theDialog, authorItem, &itemType, &itemHdl, &itemRect); SetIText(itemHdl, (StringPtr) "\pRice Dream"); GetDItem(theDialog, showsItem, &itemType, &itemHdl, &itemRect); SetIText(itemHdl, (StringPtr) "\pTracking"); do { ModalDialog(nil, &itemHit); } while (itemHit != okButton); CloseDialog(theDialog); SetPort(savePort); } static void SetupMenus () { InsertMenu (appleMenu = GetMenu (appleMenuID), 0); AddResMenu (appleMenu, (ResType) 'DRVR'); InsertMenu (fileMenu = GetMenu (fileMenuID), 0); InsertMenu (editMenu = GetMenu (editMenuID), 0); DrawMenuBar (); } static void DoMenuCommand (long mResult) { short theItem = LoWord (mResult), theMenuID = HiWord (mResult); GrafPtr savePort; Str255 daName; switch (theMenuID) { case appleMenuID: if (theItem == aboutCommand) ShowAboutBox (); else { GetItem (appleMenu, theItem, daName); GetPort (&savePort); (void) OpenDeskAcc (daName); SetPort (savePort); } break; case fileMenuID: if (theItem == quitCommand) done = true; break; case editMenuID: break; } HiliteMenu (0); } void main() { EventRecord theEvent; gxShape layoutTight, layoutNormal, layoutLoose, whiteOut; gxRunControls controls; gxLayoutOptions gxLayoutOptions; char *text1 = "track track track track track"; gxPoint posn; GDHandle max; short mbh = GetMBarHeight (); MaxApplZone(); MoreMasters(); MoreMasters(); SetGraphicsLibraryErrors(); SetGraphicsLibraryNotices (); /* GXSetValidation(gxInternalValidation | gxStructureValidation | gxNoMemoryManagerValidation); /* uncomment this for less speed and more error-checking */ InitCommonColors (); InitGraf(&thePort); InitFonts(); InitWindows(); InitMenus (); InitCursor(); SetupMenus (); /* find the deepest monitor, and make a window that just covers it */ max = GetMaxDevice (&bigRect); qdWindowRect = (**max).gdRect; /* bring it down one mbh for the header, maybe another if on main screen */ if (qdWindowRect.top == 0 && qdWindowRect.left == 0) qdWindowRect.top += mbh; qdWindowRect.top += mbh; InsetRect (&qdWindowRect, 4, 4); ShortRectToFixed (&qdWindowRect, &windowRect); myWindow = NewWindow(nil, &qdWindowRect, (StringPtr) "\pTracking Layout Sample", true, documentProc, (WindowPtr) -1L, true, 0L); myPort = GXNewWindowViewPort (myWindow); SetDefaultViewPort (myPort); /* When we want to erase the whole window, we just GXDrawShape (whiteOut). */ whiteOut = GXNewShape(gxFullType); GXSetShapeColor (whiteOut, &colorWhite); /* Make a default gxLayoutOptions and gxRunControls */ InitializeLayoutOptions (&gxLayoutOptions); InitializeRunControls (&controls); /* Position the layout half way down the left edge of the window. Set the layout's width to the window's width and set the flushness to 1/2, this will cause the layout to center in the window. */ gxLayoutOptions.width = windowRect.right - windowRect.left; gxLayoutOptions.flush = fract1/2; posn.x = 0; posn.y = (windowRect.bottom - windowRect.top) / 2; /* Build and draw the layouts. */ layoutNormal = NewSingleLayout ( text1, (char *) "\pTimes Roman", ff(32), &gxLayoutOptions, &posn, 0, &controls, nil, 0, nil); posn.y -= ff(40); controls.track = -ff(2); layoutTight = NewSingleLayout ( text1, (char *) "\pTimes Roman", ff(32), &gxLayoutOptions, &posn, 0, &controls, nil, 0, nil); posn.y += ff(80); controls.track = ff(2); layoutLoose = NewSingleLayout ( text1, (char *) "\pTimes Roman", ff(32), &gxLayoutOptions, &posn, 0, &controls, nil, 0, nil); GXDrawShape (layoutTight); GXDrawShape (layoutNormal); GXDrawShape (layoutLoose); /* Now just spin in a simple event loop until it's time to go */ while (!done) { if (WaitNextEvent(everyEvent, &theEvent, 0, nil)) { switch(theEvent.what) { case mouseDown: switch (FindWindow(theEvent.where, &whichWindow)) { case inSysWindow: SystemClick(&theEvent, whichWindow); break; case inMenuBar: DoMenuCommand (MenuSelect (theEvent.where)); break; case inDrag: DragWindow(whichWindow, theEvent.where, &screenBits.bounds); break; case inGrow: { register long newSize; newSize = GrowWindow(whichWindow, theEvent.where, &growRect); SizeWindow(whichWindow, LoWord(newSize), HiWord(newSize), true); } break; case inGoAway: if (TrackGoAway(whichWindow, theEvent.where)) done = true; break; case inContent: if (whichWindow != FrontWindow()) SelectWindow(whichWindow); break; } break; case keyDown: case autoKey: if (myWindow == FrontWindow () && theEvent.modifiers & cmdKey) DoMenuCommand (MenuKey (theEvent.message & charCodeMask)); break; case updateEvt: BeginUpdate((WindowPtr)theEvent.message); GXDrawShape (whiteOut); GXDrawShape (layoutTight); GXDrawShape (layoutNormal); GXDrawShape (layoutLoose); EndUpdate((WindowPtr)theEvent.message); break; } } } /* dispose everything we've allocated. */ GXDisposeShape(layoutTight); GXDisposeShape (layoutNormal); GXDisposeShape (layoutLoose); DisposeWindow(myWindow); GXDisposeShape (whiteOut); DisposeCommonColors (); }